group { name: "e/modules/music-control/icon";
   alias: "modules/music-control/icon";
   max: 160 160;
   set { name: "efm_drive_cd_icon";
      image { image: "efm_drive_cd_160.png" COMP; size: 81 81 16000 16000; }
      image { image: "efm_drive_cd_080.png" COMP; size: 41 41 80 80; }
      image { image: "efm_drive_cd_040.png" COMP; size: 0 0 40 40; }
   }
   parts {
      part { name: "image"; mouse_events: 0;
         description { state: "default" 0.0;
            aspect: 1.0 1.0; aspect_preference: BOTH;
            image.normal: "efm_drive_cd_icon";
         }
      }
   }
}

group { name: "e/modules/music-control/main";
   alias: "modules/music-control/main";
   set { name: "efm_drive_cd_icon";
      image { image: "efm_drive_cd_160.png" COMP; size: 81 81 16000 16000; }
      image { image: "efm_drive_cd_080.png" COMP; size: 41 41 80 80; }
      image { image: "efm_drive_cd_040.png" COMP; size: 0 0 40 40; }
   }
   parts {
      part { name: "icon";
         description { state: "default" 0.0;
            aspect: 1.0 1.0; aspect_preference: BOTH;
            image.normal: "efm_drive_cd_icon";
         }
      }
   }
}

group { name: "e/modules/music-control/popup";
   alias: "modules/music-control/popup";
#ifdef SKIP_NAMESPACE_VALIDATION
   skip_namespace_validation: 1;
#endif
   images.image: "grad-v-bi.png" COMP;
   min: 160 160;
   styles {
      style { name: "music_control_metadata_style";
         base: "font="FN" font_size=10 align=left text_class=tb_plain color=cc:/fg/normal/gadgets/music_control/text";
         tag: "title" "+ font_size=10 font="FNBD" text_class=tb_big color=cc:/fg/normal/gadgets/music_control/text/title";
         tag: "tag" "+ font_size=8 color_class=/fg/normal/gadgets/music_control/text/tag";
         tag: "br" "\n";
      }
   }
   script {
      timeprint(dst[], dstn, Float:pos, Float:fmt) {
         new h, m, s, fh, fm;
         m  = round(pos / 60.0, FLOOR);
         h  = round(float(m) / 60.0, FLOOR);
         m  = m - (h * 60);
         s  = round(pos - float((h * 3600) + (m * 60)), FLOOR);

         fm = round(fmt / 60.0, FLOOR);
         fh = round(float(fm) / 60.0, FLOOR);
         if      (fh > 0) {
            if (m >= 10) {
               if (s >= 10) snprintf(dst, dstn, "%i:%i:%i",  h, m, s);
               else         snprintf(dst, dstn, "%i:%i:0%i", h, m, s);
            } else {
               if (s >= 10) snprintf(dst, dstn, "%i:0%i:%i",  h, m, s);
               else         snprintf(dst, dstn, "%i:0%i:0%i", h, m, s);
            }
         }
         else if (fm > 0) {
            if (s >= 10) snprintf(dst, dstn, "%i:%i",  m, s);
            else         snprintf(dst, dstn, "%i:0%i", m, s);
         }
         else {
            if (s >= 10)  snprintf(dst, dstn, "0%i",  s);
            else          snprintf(dst, dstn, "%i",  s);
         }
      }
      public message(Msg_Type:type, id, ...) {
         if (id == 0) {
            new txt[128];
            getsarg(2, txt, 128);
            set_text(PART:"player_name", txt);
         } else if (id == 1) {
            new Float:pos, Float:len, txt[128];
            pos = getfarg(2);
            len = getfarg(3);

            if (len > 0.0) {
               timeprint(txt, 128, pos, len);
               set_text(PART:"pos_txt", txt);
               timeprint(txt, 128, len, len);
               set_text(PART:"len_txt", txt);

               custom_state(PART:"pos", "default", 0.0);
               set_state_val(PART:"pos", STATE_REL2, (pos / len), 1.0);
               set_state(PART:"pos", "custom", 0.0)
            } else {
               set_text(PART:"pos_txt", "");
               set_text(PART:"len_txt", "");

               custom_state(PART:"pos", "default", 0.0);
               set_state_val(PART:"pos", STATE_REL2, 0.0, 1.0);
               set_state(PART:"pos", "custom", 0.0)
            }
         }
      }
   }
   parts {
      alias: "cover_swallow" "e.cover_swallow";
      part { name: "min"; type: SPACER;
         scale: 1;
         description { state: "default" 0;
            min: 160 160;
         }
      }
      part { name: "cover_bg";
         description { state: "default" 0;
            rel1.relative: 0.25 0.25;
            rel2.relative: 0.75 0.75;
            image.normal: "efm_drive_cd_icon";
            color: 255 255 255 128; // no cc
         }
      }
      part { name: "e.cover_swallow"; type: SWALLOW;
         scale: 1;
         description { state: "default" 0;
            rel1.offset: -4 -4;
            rel2.offset: 3 3;
            offscale;
         }
      }
      part { name: "player_name_back"; type: RECT;
         scale: 1;
         description { state: "default" 0;
            color_class: "/bg/normal/gadgets/music_control/base";
            rel1.offset: -4 -4;
            rel2.offset: 3 3;
            rel2.to_y: "player_name";
            offscale;
         }
      }
      part { name: "player_mid";
         scale: 1;
         description { state: "default" 0;
            color_class: "/bg/normal/gadgets/music_control/base";
            rel1.to: "player_name_back";
            rel1.relative: 0.0 1.0;
            rel2.to: "btn_back";
            rel2.relative: 1.0 0.0;
            image.normal: "grad-v-bi.png";
         }
      }
      part { name: "btn_back"; type: RECT;
         scale: 1;
         description { state: "default" 0;
            color_class: "/bg/normal/gadgets/music_control/base";
            rel1.to_y: "previous_btn";
            rel1.offset: -4 -4;
            rel2.offset: 3 3;
            offscale;
         }
         description { state: "pressed" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/pressed/gadgets/music_control/base";
         }
      }
      part { name: "player_name"; type: TEXT;
         scale : 1;
         description { state: "default" 0;
            align: 0.5 0.0;
            color_class: "/fg/normal/gadgets/music_control/text/title";
            text.size: 10;
            text.text: "Music player";
            text.min: 0 1;
            text.font: FNBD;
            rel1.relative: 0.0 0.0;
            rel2.relative: 1.0 0.0;
            rel1.offset: 8 0;
            rel2.offset: -9 0;
            offscale;
         }
      }
      part { name: "metadata"; type: TEXTBLOCK;
         scale : 1;
         description { state: "default" 0;
            align: 0.5 0.0;
            text { style: "music_control_metadata_style";
               text: "Song Title";
               align: 0.0 0.0;
               min: 0 0;
               ellipsis: 0.0;
            }
            rel1.to_y: "player_name";
            rel1.relative: 0.0 1.0;
            rel1.offset: 8 8;
            rel2.offset: -9 8;
            offscale;
         }
      }
      part { name: "pos_txt"; type: TEXT;
         scale : 1;
         description { state: "default" 0;
            min: 64 15;
            rel.to: "btn_back";
            color_class: "/fg/normal/gadgets/music_control/text/position";
            align: 0.5 1.0;
            text.size: 10;
            text.font: FN;
            text.align: 0.0 1.0;
            text.min: 0 1;
            rel1.offset: 4 -5;
            rel2.offset: -5 -5;
            rel2.relative: 1.0 0.0;
            offscale;
         }
      }
      part { name: "len_txt"; type: TEXT;
         scale : 1;
         description { state: "default" 0;
            min: 64 15;
            rel.to: "btn_back";
            color_class: "/fg/normal/gadgets/music_control/text/length";
            align: 0.5 1.0;
            text.size: 10;
            text.font: FN;
            text.align: 1.0 1.0;
            text.min: 0 1;
            rel1.offset: 4 -5;
            rel2.offset: -5 -5;
            rel2.relative: 1.0 0.0;
            offscale;
         }
      }
      part { name: "play_btn";
         scale: 1;
         description { state: "default" 0;
            fixed: 1 1;
            min: 15 15;
            max: 15 15;
            align: 0.5 1.0;
            image.normal: "i-media-pause";
            color_class: "/fg/normal/gadgets/music_control/button/pause";
         }
         description { state: "play" 0.0;
            inherit: "default" 0.0;
            image.normal: "i-media-play";
            color_class: "/fg/normal/gadgets/music_control/button/play";
         }
      }
      part { name: "loop";
         scale: 1;
         description { state: "default" 0;
            fixed: 1 1;
            rel.to: "player_name_back";
            min: 15 15;
            max: 15 15;
            align: 1.0 0.5;
            rel1.offset: 4 4;
            rel2.offset: -5 -5;
            offscale;
            image.normal: "i-reload";
            visible: 0;
            color_class: "/fg/normal/gadgets/music_control/button/loop";
         }
         description { state: "loop" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
      }
      part { name: "previous_btn";
         scale: 1;
         description { state: "default" 0;
            fixed: 1 1;
            min: 15 15;
            max: 15 15;
            rel.to: "play_btn";
            rel1.relative: -2.0 0.0;
            rel2.relative: -1.0  1.0;
            image.normal: "i-media-prev";
            color_class: "/fg/normal/gadgets/music_control/button/prev";
         }
      }
      part { name: "next_btn";
         scale: 1;
         description { state: "default" 0;
            fixed: 1 1;
            min: 15 15;
            max: 15 15;
            rel.to: "play_btn";
            rel1.relative: 2.0 0.0;
            rel2.relative: 3.0 1.0;
            image.normal: "i-media-next";
            color_class: "/fg/normal/gadgets/music_control/button/next";
         }
      }
      part { name: "pos"; type: RECT;
         scale: 1;
         mouse_events: 0;
         description { state: "default" 0;
            fixed: 1 1;
            color_class: "/fg/normal/gadgets/music_control/progress";
            rel.to: "btn_back";
            rel1.offset: 0 -1;
            rel1.relative: 0.0 1.0;
            min: 0 5;
            align: 0.0 1.0;
         }
      }
   }
   programs {
      program { signal: "mouse,down,1"; source: "*_btn";
         action: STATE_SET "pressed" 0.0;
         target: "btn_back";
      }
      program { signal: "mouse,up,1"; source: "*_btn";
         action: STATE_SET "default" 0.0;
         transition: DECELERATE 1.0 USE_DURATION_FACTOR 1;
         target: "btn_back";
      }
      program { signal: "mouse,clicked,*"; source: "previous_btn";
         action: SIGNAL_EMIT "btn,clicked" "previous";
      }
      program { signal: "mouse,clicked,*"; source: "play_btn";
         action: SIGNAL_EMIT "btn,clicked" "play";
      }
      program { signal: "mouse,clicked,*"; source: "next_btn";
         action: SIGNAL_EMIT "btn,clicked" "next";
      }
      program { signal: "btn,state,image,play"; source: "play";
         action: STATE_SET "play" 0.0;
         transition: LINEAR 0.1;
         target: "play_btn";
      }
      program { signal: "btn,state,image,play,no_delay"; source: "play";
         action: STATE_SET "play" 0.0;
         transition: LINEAR 0.0;
         target: "play_btn";
      }
      program { signal: "btn,state,image,pause"; source: "play";
         action: STATE_SET "default" 0.0;
         transition: LINEAR 0.1;
         target: "play_btn";
      }
      program { signal: "mouse,clicked,*"; source: "player_name";
         action: SIGNAL_EMIT "label,clicked" "player_name";
      }
      program { signal: "loop,state,on"; source: "play";
         action: STATE_SET "loop" 0.0;
         target: "loop";
      }
      program { signal: "loop,state,off"; source: "play";
         action: STATE_SET "default" 0.0;
         target: "loop";
      }
   }
}
